package com.yundingai.ai.tools;

import com.yundingai.domain.entity.StudyInfo;
import com.yundingai.domain.entity.vo.ReceiveSubjectListVo;
import com.yundingai.service.StudyInfoService;
import io.lettuce.core.dynamic.annotation.Param;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: liyuxiang
 * @Date: 2025/7/28 18:16
 */
@Component
@Slf4j
public class StudentInfoFunction{
    @Autowired
    StudyInfoService studyInfoService;
    /**
     * TODO 获取用户学习信息，根据用户的学历、学习科目和学习目标，生成个性化的学习计划
     */
    @Tool(description = "查询用户学历、学习科目和学习目标信息")
    public String getStudyInfo(@Param(value = "userId") String userId) {
        log.info("查询用户学习信息: {}", userId);
        StudyInfo studyInfo = studyInfoService.selectStudyInfoVoByUserId(Integer.parseInt(userId));
        if (studyInfo == null) {
            log.warn("用户学习信息未找到，用户ID: {}", userId);
            return "错误：未找到用户学习信息，请先填写相关信息";
        }
        return studyInfo.toString();
    }

    @Tool(description = "更新用户学历、学习科目和学习目标信息")
    public String updateStudyInfo(@Param("学习信息") ReceiveSubjectListVo receiveSubjectListVo, @Param("userId") String userId) {
        log.info("更新用户学习信息: {}", receiveSubjectListVo);
        try {
            receiveSubjectListVo.setUserId(Integer.parseInt(userId));
            // 这里可以添加更多的验证逻辑
            studyInfoService.updateStudyInfo(receiveSubjectListVo);
            return "更新成功，学习信息已保存";
        } catch (Exception e) {
            log.error("更新用户学习信息失败: {}", e.getMessage());
            return "错误：更新学习信息失败，请稍后再试";
        }
    }
}
